<?php
/**
 * Created by PhpStorm.
 * User: itm-house
 * Date: 06.06.14
 * Time: 17:54
 */

class productWidget extends CWidget
{
    public $product;

    public function init()
    {

    }

    public function run()
    {
        $this->runWidget();
    }

    public function runWidget()
    {

        echo "<tr>";
        echo "<td style='width: 120px; text-align: center;'>";
        if ($this->product->image){
            echo CHtml::link("<img style='max-width: 120px !important' class='img-thumbnail' src='".Yii::app()->request->baseUrl."/images/".$this->product->image."' />", Yii::app()->createUrl("/tovar/".$this->product->id));


        }
        echo "</td>";
        echo "<td style='width: 80px;'>";
        echo "<p style='font-size: 12pt;'>" . $this->product->title . "</p>";
        echo "<p style='font-size: 10pt;'>" . $this->isPresent($this->product->is_present) . "</p>";
        echo "<p>" . CHtml::link("Подробнее", Yii::app()->createUrl("/tovar/".$this->product->id)) . "</p>";
        echo "</td>";
        if ($this->product->is_present){
        echo "<td style='min-width: 80px; vertical-align: middle; text-align: center;'>";
        echo "<p style='font-size: 14pt; color: brown;'>" . (is_numeric($this->product->price) ? number_format($this->product->price, 0, '', ' ') . " б. р." : "Цену уточняйте") . "</p>";
        echo "<p>" . CHtml::link("Отнести в улей", '#', array('class'=>'knopka-otnesti-v-ulei','submit'=>array("/dobavit_v_korzinu/"), 'params'=>array('id'=>$this->product->id))) . "</p>";
        echo "</td>";
        }



        echo "</tr>";

    }

    public function isPresent($is_present)
    {
        return $is_present ? "Есть в наличии" : "Нет в наличии";
    }
} 
